﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace ik.LongPathSupport.Test
{
    class Program
    {
        static void Main(string[] args)
        {
            string userProfile = System.Environment.GetEnvironmentVariable("UserProfile");

            string tempPath = global::LongPathSupport.Combine(userProfile, "AppData\\Local\\Temp");
            if(global::LongPathSupport.DirectoryExists(tempPath) ){
                string newFolder = tempPath;
                for(int i = 1; i<10; i++) //...10 times
                    newFolder = global::LongPathSupport.Combine(newFolder, "11111222223333344444555556666677777888889999900000"); //...50 characters...
                // path > 500 characters.
                if( !global::LongPathSupport.DirectoryExists(newFolder) )
                {
                    LongDirectoryInfo ldi = new LongDirectoryInfo(newFolder);
                    if( !ldi.Exists )
                    {
                        ldi.Create();
                    }
                    if( !ldi.Exists )
                        return;

                    LongFileInfo lfi = new LongFileInfo(global::LongPathSupport.Combine(newFolder, "testfile.txt"));
                    StreamWriter sw = lfi.CreateText();
                    sw.WriteLine("Demo of ik.LongPathSupport.\r\nSee http://ikarstein.wordpress.com");
                    sw.Close();

                    StreamReader sr = lfi.OpenText();
                    string content = sr.ReadToEnd();
                    Console.WriteLine(content);
                    sr.Close();

                    lfi.Delete();

                    global::LongPathSupport.DeleteDirectory(global::LongPathSupport.Combine(tempPath, "11111222223333344444555556666677777888889999900000"), true);
                }
            }


        }
    }
}
